public class LeetCode26 {
    public static void main(String[] args) {
        int[] nums = {1, 1, 2};

        LeetCode26 leetCode = new LeetCode26();
        System.out.println(leetCode.removeDuplicates(nums));
    }

    public int removeDuplicates(int[] nums) {
        int index = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[index]) {
                nums[++index] = nums[i];
            }
        }
        return index + 1;
    }
}
